<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LINE 1 &quot;libraries\\process\\System\\Process\\Windows.hsc&quot; #-}</span><span id="local-6989586621679048191"></span><span id="local-6989586621679048172"></span><span id="local-6989586621679047748"></span><span>
</span><span id="line-1"></span><span class="hs-pragma">{-# LANGUAGE CPP, ForeignFunctionInterface #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE InterruptibleFFI #-}</span><span>
</span><span id="line-3"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Process.Windows</span><span>
</span><span id="line-4"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">mkProcessHandle</span><span>
</span><span id="line-5"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">translateInternal</span><span>
</span><span id="line-6"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">createProcess_Internal</span><span>
</span><span id="line-7"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">withCEnvironment</span><span>
</span><span id="line-8"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">closePHANDLE</span><span>
</span><span id="line-9"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">startDelegateControlC</span><span>
</span><span id="line-10"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">endDelegateControlC</span><span>
</span><span id="line-11"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">stopDelegateControlC</span><span>
</span><span id="line-12"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">isDefaultSignal</span><span>
</span><span id="line-13"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">createPipeInternal</span><span>
</span><span id="line-14"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">createPipeInternalFd</span><span>
</span><span id="line-15"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">interruptProcessGroupOfInternal</span><span>
</span><span id="line-16"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">terminateJob</span><span>
</span><span id="line-17"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">terminateJobUnsafe</span><span>
</span><span id="line-18"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">waitForJobCompletion</span><span>
</span><span id="line-19"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">timeout_Infinite</span><span>
</span><span id="line-20"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-21"></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Process.Common</span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Concurrent</span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Exception</span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Bits</span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C</span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Marshal</span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Ptr</span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Storable</span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.IO.Unsafe</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Posix.Internals</span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Exception</span><span class="hs-cpp">
#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.SubSystem</span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Graphics.Win32.Misc</span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">GHC.Event.Windows</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">Mgr</span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.FD</span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Types</span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ClosedHandle</span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.IO.Error</span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">IOMode</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Directory</span><span>         </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">doesFileExist</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Environment</span><span>       </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">getEnv</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.FilePath</span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Win32.Console</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">generateConsoleCtrlEvent</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">cTRL_BREAK_EVENT</span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Win32.Process</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">getProcessId</span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span class="hs-comment">-- The double hash is used so that hsc does not process this include file</span><span class="hs-cpp">
#include &quot;processFlags.h&quot;
</span><span class="hs-cpp">


#if defined(i386_HOST_ARCH)
</span><span class="hs-cpp"># define WINDOWS_CCONV stdcall
</span><span class="hs-cpp">#elif defined(x86_64_HOST_ARCH)
</span><span class="hs-cpp"># define WINDOWS_CCONV ccall
</span><span class="hs-cpp">#else
</span><span class="hs-cpp"># error Unknown mingw32 arch
</span><span class="hs-cpp">#endif
</span><span>
</span><span id="line-63"></span><span class="hs-identifier">throwErrnoIfBadPHandle</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">PHANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">PHANDLE</span><span>
</span><span id="line-64"></span><span class="hs-identifier">throwErrnoIfBadPHandle</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">throwErrnoIfNull</span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span class="hs-comment">-- On Windows, we have to close this HANDLE when it is no longer required,</span><span>
</span><span id="line-67"></span><span class="hs-comment">-- hence we add a finalizer to it</span><span>
</span><span id="line-68"></span><span class="hs-identifier">mkProcessHandle</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">PHANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">PHANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ProcessHandle</span><span>
</span><span id="line-69"></span><span class="hs-identifier">mkProcessHandle</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">job</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-70"></span><span>   </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">job</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-71"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">newMVar</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">OpenHandle</span><span> </span><span class="hs-identifier">h</span><span class="hs-special">)</span><span>
</span><span id="line-72"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">newMVar</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">OpenExtHandle</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">job</span><span class="hs-special">)</span><span>
</span><span id="line-73"></span><span>   </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mkWeakMVar</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">processHandleFinaliser</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">)</span><span>
</span><span id="line-74"></span><span>   </span><span class="hs-identifier">l</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">newMVar</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-75"></span><span>   </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ProcessHandle</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">False</span><span> </span><span class="hs-identifier">l</span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span class="hs-identifier">processHandleFinaliser</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MVar</span><span> </span><span class="hs-identifier">ProcessHandle__</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-78"></span><span class="hs-identifier">processHandleFinaliser</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-79"></span><span>   </span><span class="hs-identifier">modifyMVar_</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">p_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-80"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">p_</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-81"></span><span>          </span><span class="hs-identifier">OpenHandle</span><span> </span><span class="hs-identifier">ph</span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">closePHANDLE</span><span> </span><span class="hs-identifier">ph</span><span>
</span><span id="line-82"></span><span>          </span><span class="hs-identifier">OpenExtHandle</span><span> </span><span class="hs-identifier">ph</span><span> </span><span class="hs-identifier">job</span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">closePHANDLE</span><span> </span><span class="hs-identifier">ph</span><span>
</span><span id="line-83"></span><span>                                  </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">closePHANDLE</span><span> </span><span class="hs-identifier">job</span><span>
</span><span id="line-84"></span><span>          </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-85"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">error</span><span> </span><span class="hs-string">&quot;closed process handle&quot;</span><span class="hs-special">)</span><span>
</span><span id="line-86"></span><span>
</span><span id="line-87"></span><span class="hs-identifier">closePHANDLE</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">PHANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-88"></span><span class="hs-identifier">closePHANDLE</span><span> </span><span class="hs-identifier">ph</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">c_CloseHandle</span><span> </span><span class="hs-identifier">ph</span><span>
</span><span id="line-89"></span><span>
</span><span id="line-90"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;CloseHandle&quot;</span><span>
</span><span id="line-91"></span><span>  </span><span class="hs-identifier">c_CloseHandle</span><span>
</span><span id="line-92"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">PHANDLE</span><span>
</span><span id="line-93"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-94"></span><span>
</span><span id="line-95"></span><span class="hs-identifier">createProcess_Internal</span><span>
</span><span id="line-96"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span>                     </span><span class="hs-comment">-- ^ function name (for error messages)</span><span>
</span><span id="line-97"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CreateProcess</span><span>
</span><span id="line-98"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ProcRetHandles</span><span class="hs-cpp">

#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-identifier">createProcess_Internal</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">createProcess_Internal_mio</span><span> </span><span class="hs-operator">&lt;!&gt;</span><span> </span><span class="hs-identifier">createProcess_Internal_winio</span><span class="hs-cpp">
#else
</span><span class="hs-identifier">createProcess_Internal</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">createProcess_Internal_mio</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-106"></span><span class="hs-identifier">createProcess_Internal_mio</span><span>
</span><span id="line-107"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span>                     </span><span class="hs-comment">-- ^ function name (for error messages)</span><span>
</span><span id="line-108"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CreateProcess</span><span>
</span><span id="line-109"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ProcRetHandles</span><span>
</span><span id="line-110"></span><span>
</span><span id="line-111"></span><span class="hs-identifier">createProcess_Internal_mio</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-identifier">def</span><span class="hs-glyph">@</span><span class="hs-identifier">CreateProcess</span><span class="hs-special">{</span><span>
</span><span id="line-112"></span><span>    </span><span class="hs-identifier">std_in</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_stdin</span><span class="hs-special">,</span><span>
</span><span id="line-113"></span><span>    </span><span class="hs-identifier">std_out</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_stdout</span><span class="hs-special">,</span><span>
</span><span id="line-114"></span><span>    </span><span class="hs-identifier">std_err</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_stderr</span><span class="hs-special">,</span><span>
</span><span id="line-115"></span><span>    </span><span class="hs-identifier">close_fds</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_close_fds</span><span class="hs-special">,</span><span>
</span><span id="line-116"></span><span>    </span><span class="hs-identifier">create_group</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_create_group</span><span class="hs-special">,</span><span>
</span><span id="line-117"></span><span>    </span><span class="hs-identifier">delegate_ctlc</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">_ignored</span><span class="hs-special">,</span><span>
</span><span id="line-118"></span><span>    </span><span class="hs-identifier">detach_console</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_detach_console</span><span class="hs-special">,</span><span>
</span><span id="line-119"></span><span>    </span><span class="hs-identifier">create_new_console</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_create_new_console</span><span class="hs-special">,</span><span>
</span><span id="line-120"></span><span>    </span><span class="hs-identifier">new_session</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_new_session</span><span class="hs-special">,</span><span>
</span><span id="line-121"></span><span>    </span><span class="hs-identifier">use_process_jobs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">use_job</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-122"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">createProcess_Internal_wrapper</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-identifier">def</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-123"></span><span>       </span><span class="hs-glyph">\</span><span class="hs-identifier">pfdStdInput</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">pfdStdError</span><span> </span><span class="hs-identifier">hJob</span><span> </span><span class="hs-identifier">pEnv</span><span> </span><span class="hs-identifier">pWorkDir</span><span> </span><span class="hs-identifier">pcmdline</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-124"></span><span>       </span><span class="hs-identifier">fdin</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbFd</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-identifier">fd_stdin</span><span>  </span><span class="hs-identifier">mb_stdin</span><span>
</span><span id="line-125"></span><span>       </span><span class="hs-identifier">fdout</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbFd</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-identifier">fd_stdout</span><span> </span><span class="hs-identifier">mb_stdout</span><span>
</span><span id="line-126"></span><span>       </span><span class="hs-identifier">fderr</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbFd</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-identifier">fd_stderr</span><span> </span><span class="hs-identifier">mb_stderr</span><span>
</span><span id="line-127"></span><span>
</span><span id="line-128"></span><span>       </span><span class="hs-comment">-- #2650: we must ensure mutual exclusion of c_runInteractiveProcess,</span><span>
</span><span id="line-129"></span><span>       </span><span class="hs-comment">-- because otherwise there is a race condition whereby one thread</span><span>
</span><span id="line-130"></span><span>       </span><span class="hs-comment">-- has created some pipes, and another thread spawns a process which</span><span>
</span><span id="line-131"></span><span>       </span><span class="hs-comment">-- accidentally inherits some of the pipe handles that the first</span><span>
</span><span id="line-132"></span><span>       </span><span class="hs-comment">-- thread has created.</span><span>
</span><span id="line-133"></span><span>       </span><span class="hs-comment">--</span><span>
</span><span id="line-134"></span><span>       </span><span class="hs-comment">-- An MVar in Haskell is the best way to do this, because there</span><span>
</span><span id="line-135"></span><span>       </span><span class="hs-comment">-- is no way to do one-time thread-safe initialisation of a mutex</span><span>
</span><span id="line-136"></span><span>       </span><span class="hs-comment">-- the C code.  Also the MVar will be cheaper when not running</span><span>
</span><span id="line-137"></span><span>       </span><span class="hs-comment">-- the threaded RTS.</span><span>
</span><span id="line-138"></span><span>       </span><span class="hs-identifier">proc_handle</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">withMVar</span><span> </span><span class="hs-identifier">runInteractiveProcess_lock</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-139"></span><span>                      </span><span class="hs-identifier">throwErrnoIfBadPHandle</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-140"></span><span>                           </span><span class="hs-identifier">c_runInteractiveProcess</span><span> </span><span class="hs-identifier">pcmdline</span><span> </span><span class="hs-identifier">pWorkDir</span><span> </span><span class="hs-identifier">pEnv</span><span>
</span><span id="line-141"></span><span>                                  </span><span class="hs-identifier">fdin</span><span> </span><span class="hs-identifier">fdout</span><span> </span><span class="hs-identifier">fderr</span><span>
</span><span id="line-142"></span><span>                                  </span><span class="hs-identifier">pfdStdInput</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">pfdStdError</span><span>
</span><span id="line-143"></span><span>                                  </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_close_fds</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_IN_CLOSE_FDS</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-144"></span><span>                                  </span><span class="hs-operator">.|.</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_create_group</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_IN_NEW_GROUP</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-145"></span><span>                                  </span><span class="hs-operator">.|.</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_detach_console</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_DETACHED</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-146"></span><span>                                  </span><span class="hs-operator">.|.</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_create_new_console</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_NEW_CONSOLE</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-147"></span><span>                                  </span><span class="hs-operator">.|.</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_new_session</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_NEW_SESSION</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-148"></span><span>                                  </span><span class="hs-identifier">use_job</span><span>
</span><span id="line-149"></span><span>                                  </span><span class="hs-identifier">hJob</span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span>       </span><span class="hs-identifier">hndStdInput</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbPipe</span><span> </span><span class="hs-identifier">mb_stdin</span><span>  </span><span class="hs-identifier">pfdStdInput</span><span>  </span><span class="hs-identifier">WriteMode</span><span>
</span><span id="line-152"></span><span>       </span><span class="hs-identifier">hndStdOutput</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbPipe</span><span> </span><span class="hs-identifier">mb_stdout</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">ReadMode</span><span>
</span><span id="line-153"></span><span>       </span><span class="hs-identifier">hndStdError</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbPipe</span><span> </span><span class="hs-identifier">mb_stderr</span><span> </span><span class="hs-identifier">pfdStdError</span><span>  </span><span class="hs-identifier">ReadMode</span><span>
</span><span id="line-154"></span><span>
</span><span id="line-155"></span><span>       </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">proc_handle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdInput</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdOutput</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdError</span><span class="hs-special">)</span><span>
</span><span id="line-156"></span><span>
</span><span id="line-157"></span><span>
</span><span id="line-158"></span><span class="hs-identifier">createProcess_Internal_wrapper</span><span>
</span><span id="line-159"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Storable</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">String</span><span>                     </span><span class="hs-comment">-- ^ function name (for error messages)</span><span>
</span><span id="line-160"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CreateProcess</span><span>
</span><span id="line-161"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">PHANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CWString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CWString</span><span>
</span><span id="line-162"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CWString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">PHANDLE</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">Handle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">Handle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">Handle</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-163"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ProcRetHandles</span><span>
</span><span id="line-164"></span><span>
</span><span id="line-165"></span><span class="hs-identifier">createProcess_Internal_wrapper</span><span> </span><span class="hs-identifier">_fun</span><span> </span><span class="hs-identifier">CreateProcess</span><span class="hs-special">{</span><span>
</span><span id="line-166"></span><span>    </span><span class="hs-identifier">cmdspec</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">cmdsp</span><span class="hs-special">,</span><span>
</span><span id="line-167"></span><span>    </span><span class="hs-identifier">cwd</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_cwd</span><span class="hs-special">,</span><span>
</span><span id="line-168"></span><span>    </span><span class="hs-identifier">env</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_env</span><span class="hs-special">,</span><span>
</span><span id="line-169"></span><span>    </span><span class="hs-identifier">delegate_ctlc</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">_ignored</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-170"></span><span>    </span><span class="hs-identifier">action</span><span>
</span><span id="line-171"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-172"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">lenPtr</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">sizeOf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">undefined</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">WordPtr</span><span class="hs-special">)</span><span>
</span><span id="line-173"></span><span>  </span><span class="hs-special">(</span><span class="hs-identifier">cmd</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">cmdline</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">commandToProcess</span><span> </span><span class="hs-identifier">cmdsp</span><span>
</span><span id="line-174"></span><span>  </span><span class="hs-identifier">withFilePathException</span><span> </span><span class="hs-identifier">cmd</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-175"></span><span>   </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">pfdStdInput</span><span>           </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-176"></span><span>   </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span>          </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-177"></span><span>   </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">pfdStdError</span><span>           </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-178"></span><span>   </span><span class="hs-identifier">allocaBytes</span><span> </span><span class="hs-identifier">lenPtr</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">hJob</span><span>      </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-179"></span><span>   </span><span class="hs-identifier">maybeWith</span><span> </span><span class="hs-identifier">withCEnvironment</span><span> </span><span class="hs-identifier">mb_env</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">pEnv</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-180"></span><span>   </span><span class="hs-identifier">maybeWith</span><span> </span><span class="hs-identifier">withCWString</span><span> </span><span class="hs-identifier">mb_cwd</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">pWorkDir</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-181"></span><span>   </span><span class="hs-identifier">withCWString</span><span> </span><span class="hs-identifier">cmdline</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">pcmdline</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-182"></span><span>
</span><span id="line-183"></span><span>     </span><span class="hs-special">(</span><span class="hs-identifier">proc_handle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdInput</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdOutput</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdError</span><span class="hs-special">)</span><span>
</span><span id="line-184"></span><span>       </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">action</span><span> </span><span class="hs-identifier">pfdStdInput</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">pfdStdError</span><span> </span><span class="hs-identifier">hJob</span><span> </span><span class="hs-identifier">pEnv</span><span> </span><span class="hs-identifier">pWorkDir</span><span> </span><span class="hs-identifier">pcmdline</span><span>
</span><span id="line-185"></span><span>
</span><span id="line-186"></span><span>     </span><span class="hs-identifier">phJob</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">hJob</span><span>
</span><span id="line-187"></span><span>     </span><span class="hs-identifier">ph</span><span>     </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mkProcessHandle</span><span> </span><span class="hs-identifier">proc_handle</span><span> </span><span class="hs-identifier">phJob</span><span>
</span><span id="line-188"></span><span>     </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">ProcRetHandles</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">hStdInput</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hndStdInput</span><span>
</span><span id="line-189"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hStdOutput</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hndStdOutput</span><span>
</span><span id="line-190"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hStdError</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hndStdError</span><span>
</span><span id="line-191"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">procHandle</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ph</span><span>
</span><span id="line-192"></span><span>                           </span><span class="hs-special">}</span><span class="hs-cpp">

#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-identifier">createProcess_Internal_winio</span><span>
</span><span id="line-196"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span>                     </span><span class="hs-comment">-- ^ function name (for error messages)</span><span>
</span><span id="line-197"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CreateProcess</span><span>
</span><span id="line-198"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ProcRetHandles</span><span>
</span><span id="line-199"></span><span>
</span><span id="line-200"></span><span class="hs-identifier">createProcess_Internal_winio</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-identifier">def</span><span class="hs-glyph">@</span><span class="hs-identifier">CreateProcess</span><span class="hs-special">{</span><span>
</span><span id="line-201"></span><span>    </span><span class="hs-identifier">std_in</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_stdin</span><span class="hs-special">,</span><span>
</span><span id="line-202"></span><span>    </span><span class="hs-identifier">std_out</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_stdout</span><span class="hs-special">,</span><span>
</span><span id="line-203"></span><span>    </span><span class="hs-identifier">std_err</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_stderr</span><span class="hs-special">,</span><span>
</span><span id="line-204"></span><span>    </span><span class="hs-identifier">close_fds</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_close_fds</span><span class="hs-special">,</span><span>
</span><span id="line-205"></span><span>    </span><span class="hs-identifier">create_group</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_create_group</span><span class="hs-special">,</span><span>
</span><span id="line-206"></span><span>    </span><span class="hs-identifier">delegate_ctlc</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">_ignored</span><span class="hs-special">,</span><span>
</span><span id="line-207"></span><span>    </span><span class="hs-identifier">detach_console</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_detach_console</span><span class="hs-special">,</span><span>
</span><span id="line-208"></span><span>    </span><span class="hs-identifier">create_new_console</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_create_new_console</span><span class="hs-special">,</span><span>
</span><span id="line-209"></span><span>    </span><span class="hs-identifier">new_session</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mb_new_session</span><span class="hs-special">,</span><span>
</span><span id="line-210"></span><span>    </span><span class="hs-identifier">use_process_jobs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">use_job</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-211"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">createProcess_Internal_wrapper</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-identifier">def</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-212"></span><span>       </span><span class="hs-glyph">\</span><span class="hs-identifier">pfdStdInput</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">pfdStdError</span><span> </span><span class="hs-identifier">hJob</span><span> </span><span class="hs-identifier">pEnv</span><span> </span><span class="hs-identifier">pWorkDir</span><span> </span><span class="hs-identifier">pcmdline</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-213"></span><span>
</span><span id="line-214"></span><span>     </span><span class="hs-identifier">_stdin</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getStdHandle</span><span> </span><span class="hs-identifier">sTD_INPUT_HANDLE</span><span>
</span><span id="line-215"></span><span>     </span><span class="hs-identifier">_stdout</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getStdHandle</span><span> </span><span class="hs-identifier">sTD_OUTPUT_HANDLE</span><span>
</span><span id="line-216"></span><span>     </span><span class="hs-identifier">_stderr</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getStdHandle</span><span> </span><span class="hs-identifier">sTD_ERROR_HANDLE</span><span>
</span><span id="line-217"></span><span>     </span><span class="hs-identifier">hwnd_in</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbHANDLE</span><span> </span><span class="hs-identifier">_stdin</span><span>  </span><span class="hs-identifier">mb_stdin</span><span>
</span><span id="line-218"></span><span>     </span><span class="hs-identifier">hwnd_out</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbHANDLE</span><span> </span><span class="hs-identifier">_stdout</span><span> </span><span class="hs-identifier">mb_stdout</span><span>
</span><span id="line-219"></span><span>     </span><span class="hs-identifier">hwnd_err</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbHANDLE</span><span> </span><span class="hs-identifier">_stderr</span><span> </span><span class="hs-identifier">mb_stderr</span><span>
</span><span id="line-220"></span><span>
</span><span id="line-221"></span><span>     </span><span class="hs-comment">-- #2650: we must ensure mutual exclusion of c_runInteractiveProcess,</span><span>
</span><span id="line-222"></span><span>     </span><span class="hs-comment">-- because otherwise there is a race condition whereby one thread</span><span>
</span><span id="line-223"></span><span>     </span><span class="hs-comment">-- has created some pipes, and another thread spawns a process which</span><span>
</span><span id="line-224"></span><span>     </span><span class="hs-comment">-- accidentally inherits some of the pipe handles that the first</span><span>
</span><span id="line-225"></span><span>     </span><span class="hs-comment">-- thread has created.</span><span>
</span><span id="line-226"></span><span>     </span><span class="hs-comment">--</span><span>
</span><span id="line-227"></span><span>     </span><span class="hs-comment">-- An MVar in Haskell is the best way to do this, because there</span><span>
</span><span id="line-228"></span><span>     </span><span class="hs-comment">-- is no way to do one-time thread-safe initialisation of a mutex</span><span>
</span><span id="line-229"></span><span>     </span><span class="hs-comment">-- the C code.  Also the MVar will be cheaper when not running</span><span>
</span><span id="line-230"></span><span>     </span><span class="hs-comment">-- the threaded RTS.</span><span>
</span><span id="line-231"></span><span>     </span><span class="hs-identifier">proc_handle</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">withMVar</span><span> </span><span class="hs-identifier">runInteractiveProcess_lock</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-232"></span><span>                    </span><span class="hs-identifier">throwErrnoIfBadPHandle</span><span> </span><span class="hs-identifier">fun</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-233"></span><span>                         </span><span class="hs-identifier">c_runInteractiveProcessHANDLE</span><span> </span><span class="hs-identifier">pcmdline</span><span> </span><span class="hs-identifier">pWorkDir</span><span> </span><span class="hs-identifier">pEnv</span><span>
</span><span id="line-234"></span><span>                                </span><span class="hs-identifier">hwnd_in</span><span> </span><span class="hs-identifier">hwnd_out</span><span> </span><span class="hs-identifier">hwnd_err</span><span>
</span><span id="line-235"></span><span>                                </span><span class="hs-identifier">pfdStdInput</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">pfdStdError</span><span>
</span><span id="line-236"></span><span>                                </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_close_fds</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_IN_CLOSE_FDS</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-237"></span><span>                                </span><span class="hs-operator">.|.</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_create_group</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_IN_NEW_GROUP</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-238"></span><span>                                </span><span class="hs-operator">.|.</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_detach_console</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_DETACHED</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-239"></span><span>                                </span><span class="hs-operator">.|.</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_create_new_console</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_NEW_CONSOLE</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-240"></span><span>                                </span><span class="hs-operator">.|.</span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">mb_new_session</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">RUN_PROCESS_NEW_SESSION</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-241"></span><span>                                </span><span class="hs-identifier">use_job</span><span>
</span><span id="line-242"></span><span>                                </span><span class="hs-identifier">hJob</span><span>
</span><span id="line-243"></span><span>
</span><span id="line-244"></span><span>     </span><span class="hs-comment">-- Attach the handle to the I/O manager's CompletionPort.  This allows the</span><span>
</span><span id="line-245"></span><span>     </span><span class="hs-comment">-- I/O manager to service requests for this Handle.</span><span>
</span><span id="line-246"></span><span>     </span><span class="hs-identifier">Mgr.associateHandle'</span><span> </span><span class="hs-operator">=&lt;&lt;</span><span> </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">pfdStdInput</span><span>
</span><span id="line-247"></span><span>     </span><span class="hs-identifier">Mgr.associateHandle'</span><span> </span><span class="hs-operator">=&lt;&lt;</span><span> </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span>
</span><span id="line-248"></span><span>     </span><span class="hs-identifier">Mgr.associateHandle'</span><span> </span><span class="hs-operator">=&lt;&lt;</span><span> </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">pfdStdError</span><span>
</span><span id="line-249"></span><span>
</span><span id="line-250"></span><span>     </span><span class="hs-comment">-- Create the haskell mode handles as files.</span><span>
</span><span id="line-251"></span><span>     </span><span class="hs-identifier">hndStdInput</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbPipeHANDLE</span><span> </span><span class="hs-identifier">mb_stdin</span><span>  </span><span class="hs-identifier">pfdStdInput</span><span>  </span><span class="hs-identifier">WriteMode</span><span>
</span><span id="line-252"></span><span>     </span><span class="hs-identifier">hndStdOutput</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbPipeHANDLE</span><span> </span><span class="hs-identifier">mb_stdout</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">ReadMode</span><span>
</span><span id="line-253"></span><span>     </span><span class="hs-identifier">hndStdError</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbPipeHANDLE</span><span> </span><span class="hs-identifier">mb_stderr</span><span> </span><span class="hs-identifier">pfdStdError</span><span>  </span><span class="hs-identifier">ReadMode</span><span>
</span><span id="line-254"></span><span>
</span><span id="line-255"></span><span>     </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">proc_handle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdInput</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdOutput</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdError</span><span class="hs-special">)</span><span class="hs-cpp">

#endif
</span><span>
</span><span id="line-259"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="hs-pragma">runInteractiveProcess_lock</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-260"></span><span class="hs-identifier">runInteractiveProcess_lock</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MVar</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-261"></span><span class="hs-identifier">runInteractiveProcess_lock</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">unsafePerformIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">newMVar</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-262"></span><span>
</span><span id="line-263"></span><span class="hs-comment">-- The following functions are always present in the export list. For</span><span>
</span><span id="line-264"></span><span class="hs-comment">-- compatibility with the non-Windows code, we provide the same functions with</span><span>
</span><span id="line-265"></span><span class="hs-comment">-- matching type signatures, but implemented as no-ops. For details, see:</span><span>
</span><span id="line-266"></span><span class="hs-comment">-- &lt;https://github.com/haskell/process/pull/21&gt;</span><span>
</span><span id="line-267"></span><span class="hs-identifier">startDelegateControlC</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-268"></span><span class="hs-identifier">startDelegateControlC</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-269"></span><span>
</span><span id="line-270"></span><span class="hs-identifier">endDelegateControlC</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ExitCode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-271"></span><span class="hs-identifier">endDelegateControlC</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-272"></span><span>
</span><span id="line-273"></span><span class="hs-identifier">stopDelegateControlC</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-274"></span><span class="hs-identifier">stopDelegateControlC</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-275"></span><span>
</span><span id="line-276"></span><span class="hs-comment">-- End no-op functions</span><span>
</span><span id="line-277"></span><span>
</span><span id="line-278"></span><span>
</span><span id="line-279"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-280"></span><span class="hs-comment">-- Interface to C I/O CP bits</span><span>
</span><span id="line-281"></span><span>
</span><span id="line-282"></span><span class="hs-comment">-- | Variant of terminateJob that is not thread-safe</span><span>
</span><span id="line-283"></span><span class="hs-identifier">terminateJobUnsafe</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ProcessHandle__</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CUInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-284"></span><span class="hs-identifier">terminateJobUnsafe</span><span> </span><span class="hs-identifier">p_</span><span>  </span><span class="hs-identifier">ecode</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-285"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">p_</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-286"></span><span>            </span><span class="hs-identifier">ClosedHandle</span><span>      </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">False</span><span>
</span><span id="line-287"></span><span>            </span><span class="hs-identifier">OpenHandle</span><span>        </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">False</span><span>
</span><span id="line-288"></span><span>            </span><span class="hs-identifier">OpenExtHandle</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">job</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">c_terminateJobObject</span><span> </span><span class="hs-identifier">job</span><span> </span><span class="hs-identifier">ecode</span><span>
</span><span id="line-289"></span><span>
</span><span id="line-290"></span><span class="hs-identifier">terminateJob</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ProcessHandle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CUInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-291"></span><span class="hs-identifier">terminateJob</span><span> </span><span class="hs-identifier">jh</span><span> </span><span class="hs-identifier">ecode</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-292"></span><span>    </span><span class="hs-identifier">withProcessHandle</span><span> </span><span class="hs-identifier">jh</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">p_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">terminateJobUnsafe</span><span> </span><span class="hs-identifier">p_</span><span> </span><span class="hs-identifier">ecode</span><span>
</span><span id="line-293"></span><span>
</span><span id="line-294"></span><span class="hs-identifier">timeout_Infinite</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CUInt</span><span>
</span><span id="line-295"></span><span class="hs-identifier">timeout_Infinite</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">0xFFFFFFFF</span><span>
</span><span id="line-296"></span><span>
</span><span id="line-297"></span><span class="hs-identifier">waitForJobCompletion</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">PHANDLE</span><span> </span><span class="hs-comment">-- ^ job handle</span><span>
</span><span id="line-298"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-299"></span><span class="hs-identifier">waitForJobCompletion</span><span> </span><span class="hs-identifier">job</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-300"></span><span>    </span><span class="hs-identifier">throwErrnoIf_</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-string">&quot;waitForJobCompletion&quot;</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_waitForJobCompletion</span><span> </span><span class="hs-identifier">job</span><span>
</span><span id="line-301"></span><span>
</span><span id="line-302"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-303"></span><span class="hs-comment">-- Interface to C bits</span><span>
</span><span id="line-304"></span><span>
</span><span id="line-305"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;TerminateJobObject&quot;</span><span>
</span><span id="line-306"></span><span>  </span><span class="hs-identifier">c_terminateJobObject</span><span>
</span><span id="line-307"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">PHANDLE</span><span>
</span><span id="line-308"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CUInt</span><span>
</span><span id="line-309"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-310"></span><span>
</span><span id="line-311"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">interruptible</span><span> </span><span class="hs-string">&quot;waitForJobCompletion&quot;</span><span> </span><span class="hs-comment">-- NB. safe - can block</span><span>
</span><span id="line-312"></span><span>  </span><span class="hs-identifier">c_waitForJobCompletion</span><span>
</span><span id="line-313"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">PHANDLE</span><span>
</span><span id="line-314"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-315"></span><span>
</span><span id="line-316"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;runInteractiveProcess&quot;</span><span>
</span><span id="line-317"></span><span>  </span><span class="hs-identifier">c_runInteractiveProcess</span><span>
</span><span id="line-318"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CWString</span><span>
</span><span id="line-319"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CWString</span><span>
</span><span id="line-320"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CWString</span><span>
</span><span id="line-321"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">FD</span><span>
</span><span id="line-322"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">FD</span><span>
</span><span id="line-323"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">FD</span><span>
</span><span id="line-324"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">FD</span><span>
</span><span id="line-325"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">FD</span><span>
</span><span id="line-326"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">FD</span><span>
</span><span id="line-327"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span>          </span><span class="hs-comment">-- flags</span><span>
</span><span id="line-328"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span>          </span><span class="hs-comment">-- useJobObject</span><span>
</span><span id="line-329"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">PHANDLE</span><span>       </span><span class="hs-comment">-- Handle to Job</span><span>
</span><span id="line-330"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">PHANDLE</span><span class="hs-cpp">

#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;runInteractiveProcessHANDLE&quot;</span><span>
</span><span id="line-334"></span><span>  </span><span class="hs-identifier">c_runInteractiveProcessHANDLE</span><span>
</span><span id="line-335"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CWString</span><span>
</span><span id="line-336"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CWString</span><span>
</span><span id="line-337"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CWString</span><span>
</span><span id="line-338"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-339"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-340"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-341"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-342"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-343"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-344"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span>          </span><span class="hs-comment">-- flags</span><span>
</span><span id="line-345"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span>          </span><span class="hs-comment">-- useJobObject</span><span>
</span><span id="line-346"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">PHANDLE</span><span>       </span><span class="hs-comment">-- Handle to Job</span><span>
</span><span id="line-347"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">PHANDLE</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-350"></span><span class="hs-identifier">commandToProcess</span><span>
</span><span id="line-351"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CmdSpec</span><span>
</span><span id="line-352"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">FilePath</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">String</span><span class="hs-special">)</span><span>
</span><span id="line-353"></span><span class="hs-identifier">commandToProcess</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ShellCommand</span><span> </span><span class="hs-identifier">string</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-354"></span><span>  </span><span class="hs-identifier">cmd</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">findCommandInterpreter</span><span>
</span><span id="line-355"></span><span>  </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cmd</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">translateInternal</span><span> </span><span class="hs-identifier">cmd</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-string">&quot; /c &quot;</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">string</span><span class="hs-special">)</span><span>
</span><span id="line-356"></span><span>        </span><span class="hs-comment">-- We don't want to put the cmd into a single</span><span>
</span><span id="line-357"></span><span>        </span><span class="hs-comment">-- argument, because cmd.exe will not try to split it up.  Instead,</span><span>
</span><span id="line-358"></span><span>        </span><span class="hs-comment">-- we just tack the command on the end of the cmd.exe command line,</span><span>
</span><span id="line-359"></span><span>        </span><span class="hs-comment">-- which partly works.  There seem to be some quoting issues, but</span><span>
</span><span id="line-360"></span><span>        </span><span class="hs-comment">-- I don't have the energy to find+fix them right now (ToDo). --SDM</span><span>
</span><span id="line-361"></span><span>        </span><span class="hs-comment">-- (later) Now I don't know what the above comment means.  sigh.</span><span>
</span><span id="line-362"></span><span class="hs-identifier">commandToProcess</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">RawCommand</span><span> </span><span class="hs-identifier">cmd</span><span> </span><span class="hs-identifier">args</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-363"></span><span>  </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cmd</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">translateInternal</span><span> </span><span class="hs-identifier">cmd</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">concatMap</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-char">' '</span><span class="hs-glyph">:</span><span class="hs-special">)</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">translateInternal</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">args</span><span class="hs-special">)</span><span>
</span><span id="line-364"></span><span>
</span><span id="line-365"></span><span class="hs-comment">-- Find CMD.EXE (or COMMAND.COM on Win98).  We use the same algorithm as</span><span>
</span><span id="line-366"></span><span class="hs-comment">-- system() in the VC++ CRT (Vc7/crt/src/system.c in a VC++ installation).</span><span>
</span><span id="line-367"></span><span class="hs-identifier">findCommandInterpreter</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">FilePath</span><span>
</span><span id="line-368"></span><span class="hs-identifier">findCommandInterpreter</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-369"></span><span>  </span><span class="hs-comment">-- try COMSPEC first</span><span>
</span><span id="line-370"></span><span>  </span><span class="hs-identifier">catchJust</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">e</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">isDoesNotExistError</span><span> </span><span class="hs-identifier">e</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">e</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-special">)</span><span>
</span><span id="line-371"></span><span>            </span><span class="hs-special">(</span><span class="hs-identifier">getEnv</span><span> </span><span class="hs-string">&quot;COMSPEC&quot;</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-372"></span><span>
</span><span id="line-373"></span><span>    </span><span class="hs-comment">-- try to find CMD.EXE or COMMAND.COM</span><span>
</span><span id="line-374"></span><span>    </span><span class="hs-comment">{-
    XXX We used to look at _osver (using cbits) and pick which shell to
    use with
    let filename | osver .&amp;. 0x8000 /= 0 = &quot;command.com&quot;
                 | otherwise             = &quot;cmd.exe&quot;
    We ought to use GetVersionEx instead, but for now we just look for
    either filename
    -}</span><span>
</span><span id="line-382"></span><span>    </span><span class="hs-identifier">path</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getEnv</span><span> </span><span class="hs-string">&quot;PATH&quot;</span><span>
</span><span id="line-383"></span><span>    </span><span class="hs-keyword">let</span><span>
</span><span id="line-384"></span><span>        </span><span class="hs-comment">-- use our own version of System.Directory.findExecutable, because</span><span>
</span><span id="line-385"></span><span>        </span><span class="hs-comment">-- that assumes the .exe suffix.</span><span>
</span><span id="line-386"></span><span>        </span><span class="hs-identifier">search</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">FilePath</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">FilePath</span><span class="hs-special">)</span><span>
</span><span id="line-387"></span><span>        </span><span class="hs-identifier">search</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-388"></span><span>        </span><span class="hs-identifier">search</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">d</span><span class="hs-glyph">:</span><span class="hs-identifier">ds</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-389"></span><span>                </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">path1</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">d</span><span> </span><span class="hs-operator">&lt;/&gt;</span><span> </span><span class="hs-string">&quot;cmd.exe&quot;</span><span>
</span><span id="line-390"></span><span>                    </span><span class="hs-identifier">path2</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">d</span><span> </span><span class="hs-operator">&lt;/&gt;</span><span> </span><span class="hs-string">&quot;command.com&quot;</span><span>
</span><span id="line-391"></span><span>                </span><span class="hs-identifier">b1</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">doesFileExist</span><span> </span><span class="hs-identifier">path1</span><span>
</span><span id="line-392"></span><span>                </span><span class="hs-identifier">b2</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">doesFileExist</span><span> </span><span class="hs-identifier">path2</span><span>
</span><span id="line-393"></span><span>                </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">b1</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">path1</span><span class="hs-special">)</span><span>
</span><span id="line-394"></span><span>                      </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">b2</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">path2</span><span class="hs-special">)</span><span>
</span><span id="line-395"></span><span>                                 </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">search</span><span> </span><span class="hs-identifier">ds</span><span>
</span><span id="line-396"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-397"></span><span>    </span><span class="hs-identifier">mb_path</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">search</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">splitSearchPath</span><span> </span><span class="hs-identifier">path</span><span class="hs-special">)</span><span>
</span><span id="line-398"></span><span>
</span><span id="line-399"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">mb_path</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-400"></span><span>      </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">ioError</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">mkIOError</span><span> </span><span class="hs-identifier">doesNotExistErrorType</span><span>
</span><span id="line-401"></span><span>                                </span><span class="hs-string">&quot;findCommandInterpreter&quot;</span><span> </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-special">)</span><span>
</span><span id="line-402"></span><span>      </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">cmd</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">cmd</span><span>
</span><span id="line-403"></span><span>
</span><span id="line-404"></span><span class="hs-identifier">translateInternal</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span>
</span><span id="line-405"></span><span class="hs-identifier">translateInternal</span><span> </span><span class="hs-identifier">xs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-char">'&quot;'</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">snd</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">foldr</span><span> </span><span class="hs-identifier">escape</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">True</span><span class="hs-special">,</span><span class="hs-string">&quot;\&quot;&quot;</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">xs</span><span class="hs-special">)</span><span>
</span><span id="line-406"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span class="hs-identifier">escape</span><span> </span><span class="hs-char">'&quot;'</span><span>  </span><span class="hs-special">(</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span>     </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">True</span><span class="hs-special">,</span><span>  </span><span class="hs-char">'\\'</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-char">'&quot;'</span><span>  </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span>
</span><span id="line-407"></span><span>        </span><span class="hs-identifier">escape</span><span> </span><span class="hs-char">'\\'</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">True</span><span class="hs-special">,</span><span>  </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">True</span><span class="hs-special">,</span><span>  </span><span class="hs-char">'\\'</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-char">'\\'</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span>
</span><span id="line-408"></span><span>        </span><span class="hs-identifier">escape</span><span> </span><span class="hs-char">'\\'</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">False</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">False</span><span class="hs-special">,</span><span> </span><span class="hs-char">'\\'</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span>
</span><span id="line-409"></span><span>        </span><span class="hs-identifier">escape</span><span> </span><span class="hs-identifier">c</span><span>    </span><span class="hs-special">(</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span>     </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">False</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span>
</span><span id="line-410"></span><span>        </span><span class="hs-comment">-- See long comment above for what this function is trying to do.</span><span>
</span><span id="line-411"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-412"></span><span>        </span><span class="hs-comment">-- The Bool passed back along the string is True iff the</span><span>
</span><span id="line-413"></span><span>        </span><span class="hs-comment">-- rest of the string is a sequence of backslashes followed by</span><span>
</span><span id="line-414"></span><span>        </span><span class="hs-comment">-- a double quote.</span><span>
</span><span id="line-415"></span><span>
</span><span id="line-416"></span><span class="hs-identifier">withCEnvironment</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-identifier">String</span><span class="hs-special">,</span><span class="hs-identifier">String</span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CWString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-417"></span><span class="hs-identifier">withCEnvironment</span><span> </span><span class="hs-identifier">envir</span><span> </span><span class="hs-identifier">act</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-418"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">env'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">foldr</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="hs-identifier">name</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">val</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">env0</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">name</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-special">(</span><span class="hs-char">'='</span><span class="hs-glyph">:</span><span class="hs-identifier">val</span><span class="hs-special">)</span><span class="hs-operator">++</span><span class="hs-char">'\0'</span><span class="hs-glyph">:</span><span class="hs-identifier">env0</span><span class="hs-special">)</span><span> </span><span class="hs-string">&quot;\0&quot;</span><span> </span><span class="hs-identifier">envir</span><span>
</span><span id="line-419"></span><span>  </span><span class="hs-keyword">in</span><span> </span><span class="hs-identifier">withCWString</span><span> </span><span class="hs-identifier">env'</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">act</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">castPtr</span><span class="hs-special">)</span><span>
</span><span id="line-420"></span><span>
</span><span id="line-421"></span><span class="hs-identifier">isDefaultSignal</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CLong</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-422"></span><span class="hs-identifier">isDefaultSignal</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">const</span><span> </span><span class="hs-identifier">False</span><span>
</span><span id="line-423"></span><span>
</span><span id="line-424"></span><span class="hs-identifier">createPipeInternal</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Handle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Handle</span><span class="hs-special">)</span><span class="hs-cpp">
#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-identifier">createPipeInternal</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">createPipeInternalPosix</span><span> </span><span class="hs-operator">&lt;!&gt;</span><span> </span><span class="hs-identifier">createPipeInternalHANDLE</span><span class="hs-cpp">
#else
</span><span class="hs-identifier">createPipeInternal</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">createPipeInternalPosix</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-431"></span><span class="hs-identifier">createPipeInternalPosix</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Handle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Handle</span><span class="hs-special">)</span><span>
</span><span id="line-432"></span><span class="hs-identifier">createPipeInternalPosix</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-433"></span><span>    </span><span class="hs-special">(</span><span class="hs-identifier">readfd</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">writefd</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">createPipeInternalFd</span><span>
</span><span id="line-434"></span><span>    </span><span class="hs-special">(</span><span class="hs-keyword">do</span><span> </span><span class="hs-identifier">readh</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">fdToHandle</span><span> </span><span class="hs-identifier">readfd</span><span>
</span><span id="line-435"></span><span>        </span><span class="hs-identifier">writeh</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">fdToHandle</span><span> </span><span class="hs-identifier">writefd</span><span>
</span><span id="line-436"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">readh</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">writeh</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">onException</span><span class="hs-special">`</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">close'</span><span> </span><span class="hs-identifier">readfd</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">close'</span><span> </span><span class="hs-identifier">writefd</span><span class="hs-special">)</span><span>
</span><span id="line-437"></span><span>
</span><span id="line-438"></span><span class="hs-identifier">createPipeInternalFd</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">FD</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">FD</span><span class="hs-special">)</span><span>
</span><span id="line-439"></span><span class="hs-identifier">createPipeInternalFd</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-440"></span><span>    </span><span class="hs-identifier">allocaArray</span><span> </span><span class="hs-number">2</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">pfds</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-441"></span><span>        </span><span class="hs-identifier">throwErrnoIfMinus1_</span><span> </span><span class="hs-string">&quot;_pipe&quot;</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c__pipe</span><span> </span><span class="hs-identifier">pfds</span><span> </span><span class="hs-number">8192</span><span> </span><span class="hs-special">(</span><span class="hs-number">32768</span><span class="hs-special">)</span><span>
</span><span id="line-442"></span><span class="hs-pragma">{-# LINE 442 &quot;libraries\\process\\System\\Process\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-442"></span><span>        </span><span class="hs-identifier">readfd</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">pfds</span><span>
</span><span id="line-443"></span><span>        </span><span class="hs-identifier">writefd</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peekElemOff</span><span> </span><span class="hs-identifier">pfds</span><span> </span><span class="hs-number">1</span><span>
</span><span id="line-444"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">readfd</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">writefd</span><span class="hs-special">)</span><span class="hs-cpp">

#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-identifier">createPipeInternalHANDLE</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Handle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Handle</span><span class="hs-special">)</span><span>
</span><span id="line-448"></span><span class="hs-identifier">createPipeInternalHANDLE</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-449"></span><span>  </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">pfdStdInput</span><span>  </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-450"></span><span>   </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-451"></span><span>     </span><span class="hs-identifier">throwErrnoIf_</span><span>  </span><span class="hs-special">(</span><span class="hs-operator">==</span><span class="hs-identifier">False</span><span class="hs-special">)</span><span> </span><span class="hs-string">&quot;c_mkNamedPipe&quot;</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-452"></span><span>       </span><span class="hs-identifier">c_mkNamedPipe</span><span> </span><span class="hs-identifier">pfdStdInput</span><span> </span><span class="hs-identifier">True</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">True</span><span>
</span><span id="line-453"></span><span>     </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">hndStdInput</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbPipeHANDLE</span><span> </span><span class="hs-identifier">CreatePipe</span><span> </span><span class="hs-identifier">pfdStdInput</span><span> </span><span class="hs-identifier">WriteMode</span><span>
</span><span id="line-454"></span><span>     </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">hndStdOutput</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mbPipeHANDLE</span><span> </span><span class="hs-identifier">CreatePipe</span><span> </span><span class="hs-identifier">pfdStdOutput</span><span> </span><span class="hs-identifier">ReadMode</span><span>
</span><span id="line-455"></span><span>     </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">hndStdInput</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hndStdOutput</span><span class="hs-special">)</span><span>
</span><span id="line-456"></span><span>
</span><span id="line-457"></span><span>
</span><span id="line-458"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;mkNamedPipe&quot;</span><span> </span><span class="hs-identifier">c_mkNamedPipe</span><span> </span><span class="hs-glyph">::</span><span>
</span><span id="line-459"></span><span>    </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-462"></span><span class="hs-identifier">close'</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-463"></span><span class="hs-identifier">close'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">throwErrnoIfMinus1_</span><span> </span><span class="hs-string">&quot;_close&quot;</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">c__close</span><span>
</span><span id="line-464"></span><span>
</span><span id="line-465"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;io.h _pipe&quot;</span><span> </span><span class="hs-identifier">c__pipe</span><span> </span><span class="hs-glyph">::</span><span>
</span><span id="line-466"></span><span>    </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CUInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">CInt</span><span>
</span><span id="line-467"></span><span>
</span><span id="line-468"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;io.h _close&quot;</span><span> </span><span class="hs-identifier">c__close</span><span> </span><span class="hs-glyph">::</span><span>
</span><span id="line-469"></span><span>    </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">CInt</span><span>
</span><span id="line-470"></span><span>
</span><span id="line-471"></span><span class="hs-identifier">interruptProcessGroupOfInternal</span><span>
</span><span id="line-472"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ProcessHandle</span><span>    </span><span class="hs-comment">-- ^ A process in the process group</span><span>
</span><span id="line-473"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-474"></span><span class="hs-identifier">interruptProcessGroupOfInternal</span><span> </span><span class="hs-identifier">ph</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-475"></span><span>    </span><span class="hs-identifier">withProcessHandle</span><span> </span><span class="hs-identifier">ph</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">p_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-476"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">p_</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-477"></span><span>            </span><span class="hs-identifier">ClosedHandle</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-478"></span><span>            </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">phdlProcessHandle</span><span> </span><span class="hs-identifier">p_</span><span>
</span><span id="line-479"></span><span>
</span><span id="line-480"></span><span class="hs-pragma">{-# LINE 480 &quot;libraries\\process\\System\\Process\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-480"></span><span>                    </span><span class="hs-identifier">pid</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getProcessId</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-481"></span><span>                    </span><span class="hs-identifier">generateConsoleCtrlEvent</span><span> </span><span class="hs-identifier">cTRL_BREAK_EVENT</span><span> </span><span class="hs-identifier">pid</span><span>
</span><span id="line-482"></span><span class="hs-comment">-- We can't use an #elif here, because MIN_VERSION_unix isn't defined</span><span>
</span><span id="line-483"></span><span class="hs-comment">-- on Windows, so on Windows cpp fails:</span><span>
</span><span id="line-484"></span><span class="hs-comment">-- error: missing binary operator before token &quot;(&quot;</span><span>
</span><span id="line-485"></span><span>
</span><span id="line-486"></span><span class="hs-pragma">{-# LINE 489 &quot;libraries\\process\\System\\Process\\Windows.hsc&quot; #-}</span><span>
</span><span id="line-489"></span><span>                    </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-490"></span></pre></body></html>